<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        document.onkeydown = function(event) {
            event = event || window.event;
            console.log('qianguyihao 键盘按下了');
        };

        document.onkeyup = function() {
            console.log('qianguyihao 键盘松开了');
        };
    </script>

    <input type="text" />
</body>

</html>